package o;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeBundle;
import java.util.LinkedHashMap;
import java.util.Locale;
import org.json.JSONException;
import org.json.JSONObject;

public class eeh {
    private static BroadcastReceiver ॱ = new e();

    static final class e extends SafeBroadcastReceiver {
        private e() {
        }

        public void onReceiveMsg(Context context, Intent intent) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                String action = intent.getAction();
                boolean ˎ = diu.ˊ().ˎ();
                Logger.ˎ("PushInit", "onReceive() action=" + action + " , hasAgreedPotocal is " + ˎ);
                if (!ˎ) {
                    return;
                }
                if ("android.huawei.appmarket.pushdeal.onmessagenew".equals(action)) {
                    ˏ(context, extras);
                    if (dgr.ˋ().ॱ("push")) {
                        LinkedHashMap linkedHashMap = new LinkedHashMap(2);
                        linkedHashMap.put("start_type", "push");
                        linkedHashMap.put("service_type", Integer.valueOf(ccz.ॱ()));
                        dgh.ˋ("action_start_by_type", linkedHashMap);
                        if (dok.ͺ()) {
                            cfw.ˎ(new dgt("push|" + ccz.ॱ()), new dgo("PushInit"));
                        }
                    }
                } else if ("android.huawei.appmarket.pushdeal.ontokennew".equals(action)) {
                    ˎ(context, extras);
                }
            }
        }

        private void ˎ(Context context, Bundle bundle) {
            if (doo.ˊ(context)) {
                String string = new SafeBundle(bundle).getString("token");
                epr.ˎ().ॱ(string);
                ॱ(context, string);
                SharedPreferences sharedPreferences = context.getSharedPreferences("PluginInfo", 0);
                String string2 = sharedPreferences.getString("push_token", null);
                String toLowerCase = dof.ʼ(eux.ॱ(string)).toLowerCase(Locale.getDefault());
                if (dof.ˋ(string2) || !sharedPreferences.getBoolean("is_register_succeed", false) || !string2.equals(toLowerCase)) {
                    sharedPreferences.edit().putString("push_token", toLowerCase).remove("device_token").commit();
                    new cuh().ॱ(context, string);
                }
            }
        }

        private void ॱ(Context context, String str) {
            for (cub ˏ : een.ˋ().ˎ()) {
                ˏ.ˏ(context, str);
            }
        }

        private void ˏ(Context context, Bundle bundle) {
            String string = new SafeBundle(bundle).getString("pushMsg");
            Logger.ˋ("PushInit", "onReceive() pushMsg=" + string);
            try {
                boolean ˏ;
                JSONObject jSONObject = new JSONObject(string);
                for (String str : een.ˋ().ॱ()) {
                    if (!dof.ˋ(str) && jSONObject.has(str)) {
                        if (Logger.ˎ()) {
                            Logger.ˏ("PushInit", "pushOnMsg:map has value:key =" + str);
                        }
                        Class ˊ = een.ˋ().ˊ(str);
                        Object obj = null;
                        try {
                            obj = ˊ.newInstance();
                        } catch (InstantiationException e) {
                            Logger.e("PushInit", "get PushMessageCenter handler falid" + e.getMessage());
                        } catch (IllegalAccessException e2) {
                            Logger.e("PushInit", "get PushMessageCenter handler falid" + e2.getMessage());
                        }
                        if (obj == null) {
                            continue;
                        } else if (obj instanceof cuf) {
                            ˏ = ((cuf) obj).ˏ(string);
                            break;
                        }
                    }
                }
                ˏ = false;
                if (!ˏ && jSONObject.has("cmd")) {
                    if (jSONObject.has("cmd") && !ॱ(jSONObject)) {
                        cug.ˎ(context, string);
                    }
                }
            } catch (JSONException e3) {
                Logger.ˋ("PushInit", "PushDealReceiver onReceive() JSONException : " + e3.toString());
            } catch (Exception e4) {
                Logger.ˋ("PushInit", "PushDealReceiver onReceive() Exception : " + e4.toString());
            }
        }

        private boolean ॱ(JSONObject jSONObject) {
            try {
                if ("advIntercept".equals(jSONObject.getString("cmd"))) {
                    cui.ॱ();
                    return true;
                }
            } catch (JSONException e) {
                Logger.ˋ("PushInit", "PushDealReceiver onReceive() JSONException : " + e.toString());
            }
            return false;
        }
    }

    public static void ˋ() {
        een.ˋ().ˎ(eet.class, "14");
        een.ˋ().ˎ(eeq.class, "15");
        een.ˋ().ˎ(eer.class, "2");
        een.ˋ().ˎ(eev.class, "3");
        een.ˋ().ˎ(eek.class, "5");
        een.ˋ().ˎ(eel.class, HwAccountConstants.TYPE_SINA);
        een.ˋ().ˎ(eem.class, HwAccountConstants.TYPE_SECURITY_PHONE);
        een.ˋ().ˎ(eey.class, HwAccountConstants.TYPE_TENCENT, "12");
        een.ˋ().ˎ(eep.class, "8");
        een.ˋ().ˎ(eeu.class, "11");
        een.ˋ().ˎ(ees.class, "13");
        ˊ();
    }

    public static void ˊ() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.huawei.appmarket.pushdeal.onmessagenew");
        intentFilter.addAction("android.huawei.appmarket.pushdeal.ontokennew");
        ContentManager.getInstant().getContext().registerReceiver(ॱ, intentFilter, cud.ˊ, null);
    }

    public static void ˏ() {
        ContentManager.getInstant().getContext().unregisterReceiver(ॱ);
    }
}
